package hm4;

public class Test {
    public static void main(String[] args) {
        Vehicle bicycle = new Bicycle();
        Vehicle car = new Car();
        Test test = new Test();
        test.displayAction(bicycle);
        test.displayAction(car);
    }

    public void displayAction(Vehicle vc){
        vc.soundHorn();
        if(vc instanceof Car){
            Car c = (Car) vc;
            c.openTrunk();
        }
        
        else if (vc instanceof Bicycle){
            Bicycle v = (Bicycle)  vc;
            v.pedal();
        }


    }
}

abstract class Vehicle{
    public abstract void soundHorn();
}

class Car extends Vehicle{

    @Override
    public void soundHorn() {
        System.out.println("嘀嘀嘀");
    }

    public void openTrunk(){
        System.out.println("汽车后备箱已打开");
    }
}

class Bicycle extends Vehicle{

    @Override
    public void soundHorn() {
        System.out.println("铃铃铃");
    }

    public void pedal(){
        System.out.println("正在骑自行车");
    }
}
